package com.tql.view.controller;

import com.github.pagehelper.PageInfo;
import com.tql.view.pojo.Logs;
import com.tql.view.pojo.Orderss;
import com.tql.view.service.OrderssService;
import jdk.internal.org.objectweb.asm.Handle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Transactional
public class OrderController {
 /**/@Autowired
    private OrderssService orderssService;
    @RequestMapping("/getAllOrder")
    public String getAllOrder(Model model, @RequestParam(defaultValue = "1")Integer pageNum,
                                @RequestParam(defaultValue = "15") Integer size){
        Map<String,Object> params=new HashMap<>();
        List<Orderss> list=orderssService.getAllOrder(params);
        PageInfo pageInfo=new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        return "admin/orderss";
    }
    @RequestMapping("/getAllMoney")
    @ResponseBody
    public int getAllMoney(){
        return orderssService.getAllMoney();
    }
    @RequestMapping("/toShowOrderss")
    public String toShowOrderss(){
        return "admin/showOrderss";
    }
    @RequestMapping("/getAllOrder11")
    public String getAllOrder11(Model model,
                              @RequestParam("account") String account,
                              @RequestParam("begintime") String begintime,
                              @RequestParam("endtime") String endtime) throws ParseException {
        Map<String,Object> params=new HashMap<>();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-mm-dd");
        if(begintime!=null &&begintime!=""){
            Date parse = simpleDateFormat.parse(begintime);
            params.put("begintime",parse);
        }
        if(endtime!=null &&endtime!=""){
            Date parse1 = simpleDateFormat.parse(endtime);
            params.put("endtime",parse1);
        }
        params.put("account",account);
        List<Orderss> list=orderssService.getAllOrder(params);
        PageInfo pageInfo=new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        return "admin/orderss";
    }
}
